import os
import sys

if __name__ == '__main__':
    if len(sys.argv) == 2:
        os.chdir(sys.argv[1])
        os.system('python run.py')
        os.chdir('..')
    else:
        files = os.listdir('.')
        for file in files:
            file_path = os.path.join('.', file)
            if os.path.isdir(file_path) and (not file.endswith('run_suite')):
                os.chdir(file)
                os.system('python run.py')
                os.chdir('..')
    files = os.listdir('.')
    for file in files:
        file_path = os.path.join('.', file)
        if os.path.isdir(file_path) and (not file.endswith('run_suite')):
            os.chdir(file)
            result_file = open(file+'.result', 'r')
            result = result_file.read().split(',')
            if len(result) == 1:
                print file + ' [PASS]'
            else:
                print file + ' [FAIL]\n' + '    ' + result[1] 
            result_file.close()
            os.chdir('..')